package view;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.*;
import javax.swing.event.ChangeListener;

import tabbedCanvas.LayeredCanvas;
import util.resources.*;

/**
 * 
 * A class that represents the GUI portion of the front-end module.
 * 
 * Generates the components of the GUI in conjunction with a resource file, so
 * locale and properties can easily be swapped.
 * 
 * @author wesleybrown
 * 
 */

public class View extends JFrame {

	private static final long serialVersionUID = 1L;

	private InnerFrame viewInnerFrame;
	private IOFrame IOPanel;

	/**
	 * Creates Viewer for SLogo.
	 * 
	 * @param controller Listener for execution button.
	 */

	public View (ActionListener ActionController, ChangeListener ChangeController, ActionListener viewController) {

		// Setup Resource Manager
		ResourceManager resources = ResourceManager.getInstance();
		resources.addResourcesFromFile("windowProperties");

		// Overall window properties
		setTitle(resources.getString("title"));
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		int[] windowSize = resources.getIntegerArray("windowSize");
		setMinimumSize(new Dimension(windowSize[0], windowSize[1]));
		
		BorderLayout layout = new BorderLayout();
		getContentPane().setLayout(layout);
		
		// Create Menu
		setJMenuBar(MenuBar.createMenuBar(resources, resources.getStringArray("MenuBar"), viewController));
		// add(ButtonBar.createButtonToolBar(p), BorderLayout.PAGE_START);

		// Create Tab Pane, Property Pane, Variable/History Pane
		viewInnerFrame = new InnerFrame(resources, ChangeController ,viewController);
		this.add(viewInnerFrame, BorderLayout.CENTER);
		
		// Create input pane, feedback pane
		IOPanel = new IOFrame(resources, ActionController);
		this.add(IOPanel, BorderLayout.SOUTH);
		
		
		this.pack();
		this.setVisible(true);
		IOPanel.setTextInputFocus();
	}
	
	/**
	 * 
	 * @return Get list of layered panes containing drawn vectors.
	 */
	public List<LayeredCanvas> getCanvasList(){
		return viewInnerFrame.getCanvasList();
	}
	
	/**
	 * 
	 * @return Get text contained within feedback area.
	 */
	public JTextArea getTextArea(){
		return IOPanel.getTextArea();
	}
	
	/**
	 * Auto scroll the feedback area to the bottom.
	 */
	public void scrollPaneToBottom() {
		IOPanel.scrollPaneToBottom();
	}
	
	public void addHistory(String msg){
		viewInnerFrame.addHistory(msg);
	}
	public void addVariable(String msg){
		viewInnerFrame.addVariable(msg);
	}
	
	public void cleanAndUpdate(List<String> list) {
		viewInnerFrame.cleanAndUpdate(list);
		
	}
	
}
